#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include "udp_point.h"

int main()
{
    UdpPoint* p = UdpPoint_New(8888);
    Message* msg = NULL;
    char buf[128] = {0};
    char ip[16] = {0};
    int port = 0;
    int i = 0;

    printf("p = %p\n", p);

    // sleep(5);

    // i = UdpPoint_Available(p);

    // printf("i = %i\n", i);

    msg = UdpPoint_RecvMsg(p, ip, &port);

    printf("ip: %s    port: %d\n", ip, port);
    printf("raw: %s\n", buf);

    printf("msg: %p\n", msg);

    printf("msg->type = %d\n", msg->type);
    printf("msg->cmd = %d\n", msg->cmd);
    printf("msg->index = %d\n", msg->index);
    printf("msg->total = %d\n", msg->total);

    for(i=0; i<msg->length; i++)
    {
        printf("%02X \n", msg->payload[i]);
    }

    printf("\n");

    UdpPoint_SendMsg(p, msg, ip, port);

    free(msg);

    UdpPoint_Del(p);

    return 0;
}
